package components;

import bean.GuaMap;

import javax.swing.*;
import java.awt.*;
import java.awt.geom.AffineTransform;

public class MyPanel64 extends JPanel {

    private final String binary;
    private final DataFactory dataFactory = DataFactory.getInstance();
    public MyPanel64(String binary){
        this.binary = binary;
    }

    @Override
    public void paint(Graphics g) {
        super.paint(g);
        char[] chars = binary.toCharArray();
        int y = 25;
        for (char c : chars) {
            if (c == 48) {
                g.setColor(Color.black);
                g.drawRect(25, y, 35, 8);
                g.fillRect(25, y, 35, 8);
                g.drawRect(70, y, 35, 8);
                g.fillRect(70, y, 35, 8);
            } else if (c == 49) {
                g.setColor(Color.red);
                g.drawRect(25, y, 80, 8);
                g.fillRect(25, y, 80, 8);
            }
            g.setColor(Color.black);
            GuaMap.Gua gua = dataFactory.getGuaMap().get(binary);
            if (gua.getTop().length() == 5 || gua.getTop().length() == 6){
                g.drawString(gua.getTop(),35,15);
            } else {
                g.drawString(gua.getTop(),28,15);
            }
            g.drawString(gua.getVerticalLeft().split("\n")[0],7,35);
            g.drawString(gua.getVerticalLeft().split("\n")[1],7,55);
            g.drawString(gua.getVerticalLeft().split("\n")[2],7,75);
            g.drawString(gua.getVerticalLeft().split("\n")[3],7,95);

            g.drawString(gua.getVerticalRight().split("\n")[0],110,35);
            g.drawString(gua.getVerticalRight().split("\n")[1],110,55);
            g.drawString(gua.getVerticalRight().split("\n")[2],110,75);
            g.drawString(gua.getVerticalRight().split("\n")[3],110,95);
            y += 15;
        }
    }
}
